using System.Collections.Generic;
using abilities.templates;

namespace abilities.effects
{
/**对自己或他人产生影响的效果。
*  {
*    "type" : "SPAWN_EFFECT",
*    "effects" : [...]
*  }
*/
    public class EffectSpawnEffects : Effect<EffectSpawnEffectsTemplate>
    {

        public EffectSpawnEffects(EffectSpawnEffectsTemplate t,int level) : base(t,level)
        {
        }
        
        protected override void Apply(UnitObject view, bool replay)
        {
            if (replay)
            {
                return;
            }

            UnitObject owner = (view as UnitObject);
            if (owner == null || prototype.target == null)
                return;

            // 找到了目标，把效果传给了他
            List<TargetObject> targets = prototype.target.GetTargets(new AbilityContext(this, owner.abilityManager));
            foreach (var it in targets)
            {
                //把所有的子效应都放在目标上。
                foreach (var iter in template.GetEffects())
                {
                    if (it.unit.isDead())
                    {
                        continue;
                    }
                    it.unit.abilityManager.Apply(iter, Level);
                }
            }
        }


        protected override void Cancel(UnitObject view, bool replay)
        {
            // 不能取消
        }
    }
}